﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public enum FormType
    {
        Login = 0, // 0
        Main = 1, // 1
        Subform1 = 2, // 2
        Subform2 = 3, // 2
    }

    public static class FormFactory
    {
        public static Form GetForm(FormType type)
        {
            switch (type)
            {
                case FormType.Login:
                    return new Form1();
                case FormType.Main:
                    return new Form2();
                case FormType.Subform1:
                    return new Form3();
                case FormType.Subform2:
                    return new Form4();
                default:
                    throw new Exception("未知的窗口");
            }
        }
    }

    public static class UIManager
    {
        static Stack<Form> formStack = new Stack<Form>();

        public static void LoadWindow(Form form)
        {
            if (formStack.Count != 0)
            {
                formStack.Peek().Visible = false;  //把上一个窗口隐藏
            }

            formStack.Push(form);
            form.Show();
        }

        public static void UnloadWindow()
        {
            formStack.Pop();
            if (formStack.Count != 0)
            {
                formStack.Peek().Visible = true; //把原来的窗口加载出来
            }
        }
    }
}
